package cn.cs.service;

import cn.cs.common.Dto;
import cn.cs.mapper.FaultTypeMapper;
import cn.cs.mapper.RepairOrderMapper;
import cn.cs.pojo.*;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
public class RestRepairOrderService {

    @Resource
    private RepairOrderMapper repairOrderMapper;

    @RequestMapping(value = "/getUserOrderType", method = RequestMethod.POST)
    public List<String> getUserOrderType(@RequestParam("appId") String userId) throws Exception{
        return repairOrderMapper.getUserOrderType(userId);
    }

    @RequestMapping(value = "/getAppOrderByUserId", method = RequestMethod.POST)
    public List<Map<String, Object>> getAppOrderByUserId(@RequestParam("userId") String userId) throws Exception{
        return repairOrderMapper.getAppOrderByUserId(userId);
    }

    @RequestMapping(value = "/getAppOrderByOrderState", method = RequestMethod.POST)
    public List<Map<String, Object>> getAppOrderByOrderState(@RequestParam("userId") String userId) throws Exception{
        return repairOrderMapper.getAppOrderByOrderState(userId);
    }

    @RequestMapping(value = "/getRepairOrderByOrderState", method = RequestMethod.POST)
    public List<Map<String, Object>> getRepairOrderByOrderState(@RequestParam("userId") String userId) throws Exception{
        return repairOrderMapper.getRepairOrderByOrderState(userId);
    }

    @RequestMapping(value = "/getRepairOrderList", method = RequestMethod.POST)
    public List<RepairOrder> getRepairOrderList(@RequestBody Map<String, Object> param) throws Exception{
        return repairOrderMapper.getRepairOrderList(param);
    }

    @RequestMapping(value = "/getRepairOrderListByMap", method = RequestMethod.POST)
    public List<RepairOrder> getRepairOrderListByMap(@RequestBody Map<String, Object> param) throws Exception{
        return repairOrderMapper.getRepairOrderListByMap(param);
    }

    @RequestMapping(value = "/getRepairOrderCountByMap", method = RequestMethod.POST)
    public Integer getRepairOrderCountByMap(@RequestBody Map<String, Object> param) throws Exception{
        return repairOrderMapper.getRepairOrderCountByMap(param);
    }

    @RequestMapping(value = "/addRepairOrder", method = RequestMethod.POST)
    public Integer addRepairOrder(@RequestBody RepOrder repairOrder) throws Exception{
        return repairOrderMapper.insertRepairOrder(repairOrder);
    }

    @RequestMapping(value = "/getRepOrderByAppOrderId", method = RequestMethod.POST)
    public Map<String, Object> getRepOrderByAppOrderId(@RequestParam("appOrderId") String appOrderId){
        return repairOrderMapper.getOrderByAppOrderId(appOrderId);
    }

    @RequestMapping(value = "/getClientUserById", method = RequestMethod.POST)
    public ClientUser getClientUserById(@RequestParam("id") Long id)throws Exception{
        return repairOrderMapper.getClientUserById(id);
    }

    @RequestMapping(value = "/getTestReportById", method = RequestMethod.POST)
    public Map<String, Object> getTestReportById(@RequestParam("orderNo") String orderNo)throws Exception{
        return repairOrderMapper.getTestReportById(orderNo);
    }

    @RequestMapping(value = "/getAfterOrderByOrderId", method = RequestMethod.POST)
    public List<AfterOrder> getAfterOrderByOrderId(@RequestParam("orderId") String orderId)throws Exception{
        return repairOrderMapper.getAfterOrderByOrderId(orderId);
    }

    @RequestMapping(value = "/getAppOrderByMap", method = RequestMethod.POST)
    public List<Map<String, Object>> getAppOrderByMap(@RequestBody Map<String, Object> param)throws Exception{
        return repairOrderMapper.getAppOrderByMap(param);
    }

    @RequestMapping(value = "/getAppOrderAllByMap", method = RequestMethod.POST)
    public List<Map<String, Object>> getAppOrderAllByMap(@RequestBody Map<String, Object> param)throws Exception{
        return repairOrderMapper.getAppOrderAllByMap(param);
    }

    @RequestMapping(value = "/getRepairOrderRepairUserCountByMap", method = RequestMethod.POST)
    public Integer getRepairOrderRepairUserCountByMap(@RequestBody Map<String, Object> param)throws Exception{
        return repairOrderMapper.getRepairOrderRepairUserCountByMap(param);
    }

    @RequestMapping(value = "/getAppOrderAllRepairUserByMap", method = RequestMethod.POST)
    public List<Map<String, Object>> getAppOrderAllRepairUserByMap(@RequestBody Map<String, Object> param)throws Exception{
        return repairOrderMapper.getAppOrderAllRepairUserByMap(param);
    }


    @RequestMapping(value = "/getAppOrderAgentACountByMap", method = RequestMethod.POST)
    public Integer getAppOrderAgentACountByMap(@RequestBody Map<String, Object> param)throws Exception{
        return repairOrderMapper.getAppOrderAgentACountByMap(param);
    }

    @RequestMapping(value = "/getAppOrderAgentAByMap", method = RequestMethod.POST)
    public List<RepairOrder> getAppOrderAgentAByMap(@RequestBody Map<String, Object> param)throws Exception{
        return repairOrderMapper.getAppOrderAgentAByMap(param);
    }

    @RequestMapping(value = "/getAppOrderAgentBCountByMap", method = RequestMethod.POST)
    public Integer getAppOrderAgentBCountByMap(@RequestBody Map<String, Object> param)throws Exception{
        return repairOrderMapper.getAppOrderAgentBCountByMap(param);
    }

    @RequestMapping(value = "/getAppOrderAgentBByMap", method = RequestMethod.POST)
    public List<RepairOrder> getAppOrderAgentBByMap(@RequestBody Map<String, Object> param)throws Exception{
        return repairOrderMapper.getAppOrderAgentBByMap(param);
    }

    @RequestMapping(value = "/getAppOrderAgentAProfitAll", method = RequestMethod.POST)
    public Double getAppOrderAgentAProfitAll(@RequestBody Map<String, Object> param)throws Exception{
        return repairOrderMapper.getAppOrderAgentAProfitAll(param);
    }

    @RequestMapping(value = "/getAppOrderAgentBProfitAll", method = RequestMethod.POST)
    public Double getAppOrderAgentBProfitAll(@RequestBody Map<String, Object> param)throws Exception{
        return repairOrderMapper.getAppOrderAgentBProfitAll(param);
    }

    @RequestMapping(value = "/updateRepairOrder", method = RequestMethod.POST)
    public Integer updateRepairOrder(@RequestBody RepairOrder repairOrder)throws Exception{
        return repairOrderMapper.updateRepairOrder(repairOrder);
    }

    @RequestMapping(value = "/getUserBalanceByUserId", method = RequestMethod.POST)
    public ClientUser getUserBalanceByUserId(@RequestParam("userId") String userId)throws Exception{
        return repairOrderMapper.getUserBalanceByUserId(userId);
    }

    @RequestMapping(value = "/getRepairOrderById", method = RequestMethod.POST)
    public Map<String, Object> getRepairOrderById(@RequestParam("orderNo") String orderNo)throws Exception{
        return repairOrderMapper.getRepairOrderById(orderNo);
    }

    @RequestMapping(value = "/updateAppOrderStatus", method = RequestMethod.POST)
    public Integer updateAppOrderStatus(@RequestParam("orderId") String orderId, @RequestParam("order_state") String order_state)throws Exception{
        return repairOrderMapper.updateAppOrderStatus(orderId, order_state);
    }

    @RequestMapping(value = "/insertAccoutDetails", method = RequestMethod.POST)
    public Integer insertAccoutDetails(@RequestBody AccountDetail accountDetail){
        return repairOrderMapper.insertAccoutDetails(accountDetail);
    }

    @RequestMapping(value = "/updateUserBalance", method = RequestMethod.POST)
    public Integer updateUserBalance(@RequestParam("balance") Double balance, @RequestParam("id") String id){
        return repairOrderMapper.updateUserBalance(balance, id);
    }

    @RequestMapping(value = "/getRepairsOrderById", method = RequestMethod.POST)
    public RepairOrder getRepairsOrderById(@RequestParam("id") String id) throws Exception{
        return repairOrderMapper.getRepOrderById(id);
    }

    @RequestMapping(value = "/updateUserOrderNumber", method = RequestMethod.POST)
    public Integer updateUserOrderNumber(@RequestParam("id") String id) throws Exception{
        return repairOrderMapper.updateUserOrderNumber(id);
    }

    @RequestMapping(value = "/getOrderByRepUserId", method = RequestMethod.POST)
    public List<Map<String, Object>> getOrderByRepUserId(@RequestParam("rep_user_id") String rep_user_id)throws Exception{
        return repairOrderMapper.getOrderByRepUserId(rep_user_id);
    }

    @RequestMapping(value = "/updateRepOrderStatusMoney", method = RequestMethod.POST)
    public Integer updateRepOrderStatusMoney(@RequestBody Map<String, Object> param)throws Exception{
        return repairOrderMapper.updateRepOrderStatusMoney(param);
    }

    @RequestMapping(value = "/updateRapairOrderStatus", method = RequestMethod.POST)
    public Integer updateRapairOrderStatus(@RequestBody RepOrder repOrder){
        return repairOrderMapper.updateRapairOrderStatus(repOrder);
    }

    //支付成功修改检测报告订单状态
    @RequestMapping(value = "/updateTestReportStatus", method = RequestMethod.POST)
    public Integer updateTestReportStatus(@RequestParam("rep_order_id") String rep_order_id, @RequestParam("app_order_id") String app_order_id, @RequestParam("id") String id)throws Exception{
        return repairOrderMapper.updateTestReportStatus(rep_order_id, app_order_id, id);
    }

    @RequestMapping(value = "/getBillOrderDetailsByOrderId", method = RequestMethod.POST)
    public Map<String, Object> getBillOrderDetailsByOrderId(@RequestParam("orderId") String OrderId){
        return repairOrderMapper.getBillOrderDetailsByOrderId(OrderId);
    }

    @RequestMapping(value = "/getBillOrderImgByOrderId", method = RequestMethod.POST)
    public List<Map<String, Object>> getBillOrderImgByOrderId(@RequestParam("orderId") String OrderId){
        return repairOrderMapper.getBillOrderImgByOrderId(OrderId);
    }

    @RequestMapping(value = "/updateOrderStatusByAppId", method = RequestMethod.POST)
    public Integer updateOrderStatusByAppId(@RequestParam("order_state") String order_state, @RequestParam("appId") String appId){
        return repairOrderMapper.updateOrderStatusByAppId(order_state, appId);
    }

    @RequestMapping(value = "/getInsurancePremiumCount", method = RequestMethod.POST)
    public Map<String, Object> getInsurancePremiumCount(@RequestBody Map<String, Object> param) throws Exception{
        return repairOrderMapper.getInsurancePremiumCount(param);
    }

    @RequestMapping(value = "/getInsurancePremiumByMap", method = RequestMethod.POST)
    public List<Map<String, Object>> getInsurancePremiumByMap(@RequestBody Map<String, Object> param) throws Exception{
        return repairOrderMapper.getInsurancePremiumByMap(param);
    }

    @RequestMapping(value = "/updateRepairUserStar", method = RequestMethod.POST)
    public Integer updateRepairUserStar(@RequestParam(value = "star") Long star, @RequestParam(value = "orderId") String orderId){
        return repairOrderMapper.updateRepairUserStar(star, orderId);
    }

    @RequestMapping(value = "/updateOrderStateAAgent", method = RequestMethod.POST)
    public Integer updateOrderStateAAgent(@RequestParam("id)") String id)throws Exception{
        return repairOrderMapper.updateOrderStateAAgent(id);
    }

    @RequestMapping(value = "/updateOrderStateBAgent", method = RequestMethod.POST)
    public Integer updateOrderStateBAgent(@RequestParam("id)") String id)throws Exception{
        return repairOrderMapper.updateOrderStateBAgent(id);
    }

    @RequestMapping(value = "/getAppOrderAgentAProfitAllNew", method = RequestMethod.POST)
    public Double getAppOrderAgentAProfitAllNew(@RequestBody Map<String, Object> param)throws Exception{
        return repairOrderMapper.getAppOrderAgentAProfitAllNew(param);
    }

    @RequestMapping(value = "/getAppOrderAgentAByMapNew", method = RequestMethod.POST)
    public List<Map<String, Object>> getAppOrderAgentAByMapNew(@RequestBody Map<String, Object> param)throws Exception{
        return repairOrderMapper.getAppOrderAgentAByMapNew(param);
    }

    @RequestMapping(value = "/getOrderById", method = RequestMethod.POST)
    public Map<String, Object> getOrderById(@Param(value = "id") String id)throws Exception{
        return repairOrderMapper.getOrderById(id);
    }

    @RequestMapping(value = "/updateOrderStatus", method = RequestMethod.POST)
    public Integer updateOrderStatus(@Param(value = "id") String id, @Param(value = "app_order_id") String app_order_id, @Param(value = "agentAId") String agentAId, @Param(value = "agentBId") String agentBId)throws Exception{
        return repairOrderMapper.updateOrderStatus(id, app_order_id, agentAId, agentBId);
    }


}
